package manage.action;

import m.system.db.TransactionManager;
import m.system.util.JSONMessage;
import manage.model.StatusModel;
import manage.service.StatusService;

public abstract class StatusAction extends ManageAction{

	public abstract StatusModel getModel();
	public abstract String[] getStatusPower();
	/**
	 * 恢复
	 *
	 */
	public JSONMessage doRecovery(){
		JSONMessage message=new JSONMessage();
		TransactionManager tm=new TransactionManager();
		try {
			tm.begin();
			verifyAdminOperPower(getStatusPower());
			getService(StatusService.class).doRecovery(getModel());
			doRecoveryCallback();
			fillJSONResult(message,true,"已恢复");
			tm.commit();
		} catch (Exception e) {
			tm.rollback();
			fillJSONResult(message,false,e);
		}
		return message;
	}
	public void doRecoveryCallback() throws Exception { }
	/**
	 * 停用
	 *
	 */
	public JSONMessage doDisable(){
		JSONMessage message=new JSONMessage();
		TransactionManager tm=new TransactionManager();
		try {
			tm.begin();
			verifyAdminOperPower(getStatusPower());
			getService(StatusService.class).doDisable(getModel());
			doDisableCallback();
			fillJSONResult(message,true,"已停用");
			tm.commit();
		} catch (Exception e) {
			tm.rollback();
			fillJSONResult(message,false,e);
		}
		return message;
	}
	public void doDisableCallback() throws Exception{ }
}
